<?php
/*
+-----------------------------------------------------------------------------+
| $Id: *.php 2009-08-18 08:41:22Z Bleakwind $
| Copyright (c) 2003-2010 Bleakwind (www.weaverdream.com)
| http://www.weaverdream.com/
+-----------------------------------------------------------------------------+
*/

if (!defined( 'ENTRY_INDEX')){
    echo "<h1>Forbidden</h1><p>You don't have permission to access on this server.</p>";
    exit;
}

$t->set_file("f_message", "message.htm");

if($sys->get['han'] == "save"){
    if ($sys->post['area'] == "" ||
        $sys->post['subject'] == "" ||
        $sys->post['content'] == ""){
        $sys->prompt("failed","表单没有填写完整!");
    }else{

        $list = array();
        if($sys->post['area'] == "area_all"){
            $sql = "SELECT id FROM ".DB_TABLE_MEMBER." ORDER BY id";
            $result = &$db->Execute($sql);
            while($db->next_record()){
                $list[] = $result->fields['id'];
            }
        }elseif($sys->post['area'] == "area_alone"){
            $list_username = explode(",",$sys->post['area_alone_input']);
            foreach($list_username as $value){
                $sql = "SELECT id FROM ".DB_TABLE_MEMBER." WHERE username='".$value."'";
                $result = &$db->Execute($sql);
                if($db->next_record()){
                    $list[] = $result->fields['id'];
                }
            }
        }

        $number = count($list);
        for($i=0;$i<$number;$i++){
            $sql = "INSERT INTO ".DB_TABLE_PM." SET
                       type   ='1',
                       subject='".addslashes($sys->post['subject'])."',
                       content='".addslashes($sys->post['content'])."',
                       fid    =0,
                       tid    =".$list[$i].",
                       rid    =0,
                       if_read=0,
                       time   =".$sys->nowtime."
                   ";
            $result = &$db->Execute($sql);
        }

        $sys->prompt("succeed","群发短信成功!", $CONFIGURE['common']['control_admin']."?act=message&pag=".$sys->get['page']."");

    }
}

$t->assign("var_runtime", $bwruntime->totaltime());
$t->parse("message","f_message");
$t->p("message");
?>
